home *** CD-ROM | disk | FTP | other *** search
- // Written by: Robert B. Cooper
- // ELECTRON Software
- // P.O. Box 309
- // Mt. Storm, WV. 26739
- // CompuServe ID#: 73244,3472
- // America OnLine: ELECTRON
- //
- // Main program file for the Custom Cursor DLL Demonstration.
- // This Demo was written in with Microsoft Visual C++ Ver. 1.0
- // It can be compiled with any ANSI C standard compiler except you will
- // need to modify the .MAK file that is included.
- //
- // You have a royalty-free right to use, modify, reproduce and distribute the
- // Sample Files CUS_CUR.C, CUR_DLL.DEF, CUS_CUR.H, SAMPLE.RC, RESOURCE.H and
- // CUR_DEMO.MAK(and/or any modified version) in any way you find useful,
- // provided that you agree that ELECTRON SOFTWARE has no warranty obligations
- // or liability for any Sample Application Files which are modified.
-
-
- #include <windows.h>
- #include "Cus_Cur.h"
- #include "Resource.h"
-
- HANDLE hInst; // Program instance handle.
- HANDLE hCursor; // Custom Cursor handle.
- HANDLE hLibrary; // Handle to the CURSOR.DLL.
-
- int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- { char szAppName[]="Cur_Demo";
- int xScreen, yScreen;
- WNDCLASS wndclass;
- HWND hWnd;
- MSG msg;
- xScreen = GetSystemMetrics(SM_CXSCREEN);
- yScreen = GetSystemMetrics(SM_CYSCREEN);
- // This next line loads the Custom Cursor DLL into memory and stores
- // the returned value in the hLibrary handle. This example does not
- // use any error handling routines. For your application I strongly
- // suggest that you include this feature.
- hLibrary = LoadLibrary("CURSOR.DLL");
- // The LoadCursor function now loads the PENCIL_NW_A from the CURSOR.DLL
- // The returned value is a handle the the custom cursor and is stored in
- // the hCursor handle.
- hCursor = LoadCursor(hLibrary, "POINTER_NW");
- if (!hPrevInstance)
- { wndclass.style = CS_HREDRAW | CS_VREDRAW;
- wndclass.lpfnWndProc = WndProc;
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
- wndclass.hInstance = hInstance;
- wndclass.hIcon = LoadIcon(hInstance, "ID_ATOM"); // Loads the program icon.
- wndclass.hCursor = NULL; // Sets the default cursor to NULL so that
- // you can use a custom cursor.
- wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
- wndclass.lpszMenuName = "SampleMenu"; // The menu resource identifier.
- wndclass.lpszClassName = szAppName; // Name used in call to CreateWindow.
- if (!RegisterClass(&wndclass)) return FALSE;
- }
- hInst = hInstance;
- hWnd = CreateWindow( szAppName, " Custom Cursor Demonstration in Microsoft C", // Text for window title bar.
- WS_OVERLAPPEDWINDOW, // Window style.
- 0, // Initial x position
- 0, // Initial y position.
- xScreen, // Width.
- yScreen, // Height.
- NULL, // Parent window handle.
- NULL, // Window menu handle.
- hInstance, // Program instance handle.
- NULL // Create parameters.
- );
-
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- SetCursor(hCursor); // Sets the cursor shown when the program first starts
- // to the custom cursor.
-
- while (GetMessage(&msg, NULL, 0, 0))
- { TranslateMessage(&msg); // Translates virtual key codes
- DispatchMessage(&msg); // Dispatches message to window
- }
- return msg.wParam; // Returns the value from PostQuitMessage
- }
-
- long FAR PASCAL _export WndProc(HWND hWnd, UINT message,
- WPARAM wParam, LPARAM lParam)
- {
- static RECT rect;
- static int xScreen, yScreen, LButtonPressed, RButtonPressed;
- PAINTSTRUCT ps;
- HDC hDC, hdcMem;
-
- switch (message)
- {
- case WM_PAINT:
- hDC = BeginPaint(hWnd, &ps);
- hdcMem = CreateCompatibleDC(hDC);
- DeleteDC(hdcMem);
- EndPaint(hWnd, &ps);
- LButtonPressed = RButtonPressed = 0;
- break;
- case WM_SIZE:
- xScreen = LOWORD(lParam);
- yScreen = HIWORD(lParam);
- LButtonPressed = RButtonPressed = 0;
- break;
- case WM_LBUTTONDOWN:
- LButtonPressed = 1;
- rect.left = LOWORD(lParam);
- rect.top = HIWORD(lParam);
- InvalidateRect(hWnd, &rect, FALSE);
- break;
- case WM_RBUTTONDOWN:
- RButtonPressed = 1;
- rect.left = LOWORD(lParam);
- rect.top = HIWORD(lParam);
- InvalidateRect(hWnd, &rect, FALSE);
- // Returns the Cursor to the type when the demonstration first started.
- hCursor = LoadCursor(hLibrary, "POINTER_NW");
- SetCursor(hCursor);
- break;
- // The WM_MOUSEMOVE Event is called each time the mouse moves to ensure
- // that the cursor stays defined to the current custom cursor
- case WM_MOUSEMOVE:
- SetCursor(hCursor);
- break;
- // The WM_COMMAND Event is called when the user chooses a menu item.
- // Each menu item in this demo has a different cursor associated with it.
- // IDM_EXIT closes the program and initiates the WM_DESTROY Event.
- // The About Dialog Box is not functional in this demo.
- case WM_COMMAND:
- switch (wParam)
- {
- case IDM_PRINT:
- hCursor = LoadCursor(hLibrary, "PRINTER");
- SetCursor(hCursor);
- break;
- case IDM_EXIT:
- SendMessage(hWnd, WM_CLOSE, 0, 0L);
- return 0;
- break;
- case IDM_CUT:
- hCursor = LoadCursor(hLibrary, "SCISSORS_NW");
- SetCursor(hCursor);
- break;
- case IDM_COPY:
- hCursor = LoadCursor(hLibrary, "HAND_DRAG_1");
- SetCursor(hCursor);
- break;
- case IDM_PASTE:
- hCursor = LoadCursor(hLibrary, "PIN_NW");
- SetCursor(hCursor);
- break;
- case IDM_LINE:
- hCursor = LoadCursor(hLibrary, "DRAW_LINE");
- SetCursor(hCursor);
- break;
- case IDM_CIRCLE:
- hCursor = LoadCursor(hLibrary, "DRAW_CIRCLE");
- SetCursor(hCursor);
- break;
- case IDM_FREEHAND:
- hCursor = LoadCursor(hLibrary, "DRAW_FREEHAND");
- SetCursor(hCursor);
- break;
- case IDM_PAINT:
- hCursor = LoadCursor(hLibrary, "PAINT_BRUSH_SW");
- SetCursor(hCursor);
- break;
- case IDM_CONTEXTHELP:
- hCursor = LoadCursor(hLibrary, "CONTEXT_HELP");
- SetCursor(hCursor);
- break;
- case IDM_ABOUT:
- return 0;
- break;
- }
- break;
- break;
- case WM_DESTROY:
- FreeLibrary(hLibrary);
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0L;
- }